<template>
	<view>
		<uni-swiper-dot class="swiper" :info="info" :current="current" field="content" :mode="mode">
			<swiper class="swiper-box" @change="change" circular autoplay interval="3000">
				<swiper-item v-for="(item ,index) in info" :key="index">
					<view class="swiper-item">
						<image :src="item.image" mode="aspectFill"></image>
					</view>
				</swiper-item>
			</swiper>
			<text class="title">小锦李 ♥ 小黄鸭</text>
			<view :class="isPlay ? 'active' : ''  " class="music" @click="playAudio">
				<image style="width: 64rpx;" src="../../static/image/music.png" mode="widthFix"></image>
				<text class="slash" v-if="!isPlay"></text>
			</view>
		</uni-swiper-dot>
		<view class="content">
			<view class="map" @click="gotoSeeMap">
				<image src="../../static/image/zb.png" mode="aspectFit"></image>
				<text>人民大会堂</text>
				<image src="../../static/image/右箭头.png" mode=""></image>
			</view>
			<view class="time map">
				<image src="../../static/image/shijian.png" mode="aspectFit"></image>
				<text>2024年10月1日 11:30</text>
			</view>
			<view class="explain map">
				<image src="../../static/image/shuoming.png" mode="aspectFit"></image>
				<text>活动说明</text>

			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: [{
					image: 'https://mypic-1314846466.cos.ap-nanjing.myqcloud.com/banner.jpg'
				}, {
					image: 'https://mypic-1314846466.cos.ap-nanjing.myqcloud.com/2.jpg'
				}, {
					image: 'https://mypic-1314846466.cos.ap-nanjing.myqcloud.com/3.jpg'
				}],
				current: 0,
				mode: 'round',
				bgcAudioContext: '',
				isPlay: true
			};
		},
		onLoad() {
			wx.showShareMenu({
				withShareTicket: true, // 是否使用带 shareTicket 的转发。如果是，点击分享消息之后会跳转到小程序的来源页面，并可以在onLoad的options中获取到shareTicket
				menus: ['shareAppMessage', 'shareTimeline'] // 需要显示的分享按钮
			})
		},
		mounted() {

			if (!this.bgcAudioContext) {
				console.log(this.bgcAudioContext, '56');
				this.palyAuido()
			} else {
				console.log(this.bgcAudioContext, '59');
			}

		},
		beforeDestroy() {
			this.innerAudioContext.stop()
		},
		methods: {
			// 播放音乐
			palyAuido() {
				this.innerAudioContext = wx.createInnerAudioContext()
				const innerAudioContext = this.innerAudioContext
				innerAudioContext.autoplay = true
				innerAudioContext.src =
					'https://mypic-1314846466.cos.ap-nanjing.myqcloud.com/us/Perfect%20%28Acoustic%29-Ed%20Sheeran.mp3'
				innerAudioContext.onPlay(() => {
					console.log('开始播放')
				})
				innerAudioContext.onError((res) => {
					console.log(res.errMsg)
					console.log(res.errCode)
				})
				this.audio = innerAudioContext
			},
			playAudio() {
				if (this.isPlay) {
					console.log(this.innerAudioContext, '77')
					this.innerAudioContext.pause()
					this.isPlay = false
				} else {
					console.log(this.innerAudioContext, '81');
					this.innerAudioContext.play()
					this.isPlay = true

				}

			},
			change(e) {
				this.current = e.detail.current;
			},
			gotoSeeMap() {
				uni.navigateTo({
					url: '/pages/map/index'
				})
			}
		}
	}
</script>

<style lang="less">
	@keyframes rotate {
		0% {
			transform: rotate(0deg);
		}

		100% {
			transform: rotate(360deg);
		}
	}

	.swiper {
		width: 100vw;

		.swiper-box {
			height: 480rpx;
		}

		.swiper-item image {
			width: 100%;

		}

		.active {
			animation: rotate 5s linear infinite;
		}

		.music {
			position: absolute;
			right: 40rpx;
			top: 40rpx;
			border-radius: 50%;

			.slash {
				position: relative;
				top: -40rpx;
				transform: rotate(45deg);
				width: 80rpx;
				height: 2px;
				display: block;
				background-color: #7f89e3;
				// transform-origin: left center;
			}
		}

		.title {
			display: block;
			position: relative;
			top: -100rpx;
			background-color: rgba(1, 1, 1, 0.5);
			text-align: center;
			width: 100vw;
			height: 100rpx;
			line-height: 100rpx;
			color: #ff0000;
			font-weight: bold;
		}
	}

	.content {

		.map {
			padding: 0 1rem;
			height: 100rpx;
			border: 1px solid #eee;
			display: flex;
			align-items: center;

			image {
				width: 1rem;
				height: 1rem;
				padding-right: 1rem;
			}

			text {
				flex: 1;
			}
		}

	}
</style>